package com.zhan.ielts.task;

import com.zhan.ielts.service.article.ArticleService;
import com.zhan.ielts.service.article.CategroyService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.List;

@Component
public class ArticleJob {
    @Autowired
    private CategroyService service;

    @Autowired
    private ArticleService articleService;

    private Logger log = LoggerFactory.getLogger(ArticleJob.class);

    @Scheduled(cron = "0 0 5 * * ?")
    public void run() {
        String resourcePath = System.getenv("resources_path");
		if(!"dev".equals(resourcePath)){
        log.info("start ArticleJob:" + new Date());
        List<String> catidList = service.getCategoryDataFromServer();
        articleService.updateArticle(catidList);
        articleService.insertHotArticle();
        log.info("end ArticleJob:" + new Date());
		}
    }
}
